﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BeerManagementSystem
{
    public partial class Administration : Form
    {
        private SQLConnector _sqlConnector;
        private Controller _controller;
        private Beerbill _beerbill;
        private Payment _payment;
        private CashTransactionsManager _cashTransactionsManager;
        private BeerdocterControl _beerdocterControl;
        private TransactionsManager _transactionsManager;
        
        public Administration(Controller controller)
        {
            InitializeComponent();
            _sqlConnector = new SQLConnector();
            this._controller = controller;
            beerbillMonth.SelectedItem = DateTime.Now.Month;
        }

        private void optionsButton_Click(object sender, EventArgs e)
        {
            var settingsDialog = new Settings();
            settingsDialog.Show();
        }

        private void resetMonthButton_Click(object sender, EventArgs e)
        {
            _sqlConnector.ResetBeerMonth();
        }

        private void resetDayButton_Click(object sender, EventArgs e)
        {
            _sqlConnector.ResetBeerDay();
        }

        private void userButton_Click(object sender, EventArgs e)
        {
            var umanage = new UserManager();
            umanage.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _controller.UpdateWebUsers();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            _controller.UpdateUserAccountBeerbill();
        }


        private void button7_Click(object sender, EventArgs e)
        {
            _payment = new Payment();
            _payment.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            _transactionsManager = new TransactionsManager();
            _transactionsManager.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _beerdocterControl = new BeerdocterControl();
            _beerdocterControl.Show();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            _cashTransactionsManager = new CashTransactionsManager();
            _cashTransactionsManager.Show();
        }

        

        private void button4_Click(object sender, EventArgs e)
        {
            if (beerbillMonth.SelectedItem == null || beerbillYear.SelectedItem == null)
                MessageBox.Show("Datum eintragen");
            else
            {
                int month, year;
                month = beerbillMonth.SelectedItem != null ? int.Parse(beerbillMonth.SelectedItem.ToString()) : DateTime.Now.Month;
                year = beerbillYear.SelectedItem != null ? int.Parse(beerbillYear.SelectedItem.ToString()) : DateTime.Now.Year;
                DateTime date = new DateTime(year, month, 1);
                _controller.WriteBeerbill(date);
            }
            
        }

        private void SendBeerbillButton_Click(object sender, EventArgs e)
        {
            _beerbill = new Beerbill(_sqlConnector.GetAllMailadresses());
            _beerbill.Show();
        }
    }
}
